import 'package:flutter/material.dart';
import 'package:flutter_jojo_test/common/resource/color.dart';
import 'package:flutter_jojo_test/common/utils/ex.dart';
import 'package:get/get.dart';
import 'package:flutter_jojo_test/common/base/base_controller.dart';
import 'state.dart';

class MainLogic extends BaseController with WidgetsBindingObserver {
  final MainState state = MainState();

  @override
  void onReady() {
    // TODO: implement onReady
    super.onReady();
    WidgetsBinding.instance?.addObserver(this);

    ever(state.index, (value) {
      //切换tab
      state.controller.jumpToPage(state.index.value);
    });
    state.index.value = 0;
  }

  @override
  void onClose() {
    // TODO: implement onClose
    super.onClose();
    WidgetsBinding.instance?.removeObserver(this);
  }

  @override
  void didChangePlatformBrightness() {
    super.didChangePlatformBrightness();
    changeTheme();
  }

  ///更改主题色
  void changeTheme() {
    if (isDarkMode()) {
      ThemeColor.g1.value = const Color(0xffffffff);
      ThemeColor.g2.value = const Color(0xFF11183F);
      ThemeColor.t1.value = const Color(0xffffffff);
    } else {
      ThemeColor.g1.value = const Color(0xff0C1231);
      ThemeColor.g2.value = const Color(0xFF11183F);
      ThemeColor.t1.value = const Color(0xff333333);
    }
  }
}
